#!/usr/bin/env python

from oslo_config import cfg
from os.path import join, dirname
from os import environ
import sys
conf = cfg.CONF

default_opts = [
    cfg.StrOpt(name="env", default="debug"),  # 环境变量值
    cfg.StrOpt(name="environ", default="environ"),  # 环境变量key
    cfg.BoolOpt(name='debug',default=False)
]
conf.register_opts(default_opts)
conf.register_cli_opts([
    cfg.IntOpt(name='port', default=8888),
])

# sqlalchemy
sqlalchemy = cfg.OptGroup(name='sqlalchemy', title="MySQL ORM 相关配置")
conf.register_group(sqlalchemy)
conf.register_cli_opts([
    cfg.BoolOpt('echo', default=True),
    cfg.BoolOpt('autoflush', default=True),
    cfg.IntOpt('pool_size', 10),
    cfg.IntOpt('pool_recycle', 3600)
], sqlalchemy)

# mysql
mysql = cfg.OptGroup(name='mysql', title="MySQL DSN配置")
conf.register_group(mysql)
conf.register_cli_opts([
    cfg.StrOpt('host', default='localhost'),
    cfg.StrOpt('user', default='root'),
    cfg.IntOpt('port', default=3306),
    cfg.StrOpt('password', default='root'),
    cfg.StrOpt('database', default='demo'),
    cfg.StrOpt('charset', default='utf8mb4')
], mysql)

#redis
redis = cfg.OptGroup(name='redis', title="Redis 相关配置")
conf.register_group(redis)
conf.register_cli_opts([
    cfg.StrOpt('host', default='127.0.0.1'),
    cfg.IntOpt('port', default=6379),
    cfg.StrOpt('password', default='')
], redis)

#mongo
mongo = cfg.OptGroup(name='mongo', title="mongo 相关配置")
conf.register_group(mongo)
conf.register_cli_opts([
    cfg.StrOpt('host', default='127.0.0.1'),
    cfg.IntOpt('port', default=27017),
    cfg.StrOpt('user', default='root'),
    cfg.StrOpt('pwd', default='123456'),
    cfg.StrOpt('pool_size', default=100)
], mongo)


#token
token = cfg.OptGroup(name='token', title="接口加解密配置")
conf.register_group(token)
conf.register_cli_opts([
    cfg.StrOpt('token', default='')
], token)

#APP应用配置
app = cfg.OptGroup(name='app', title="app配置")
conf.register_group(app)
conf.register_cli_opts([
    cfg.StrOpt('app_name', default=''),
    cfg.StrOpt('app_static', default='')
], app)

env = environ.get(conf.environ, 'prod')
print('运行环境:',env)
env = env if env in ['debug', 'prod', 'pre'] else 'prod'
conf(default_config_files=[join(dirname(__file__), '.'.join([env, 'ini']))])

